package com.mapper;

import com.pojo.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {
    @Select("SELECT * FROM `order` WHERE user_id = #{userId}")
    List<Order> findByUserId(Long userId);
    @Select("SELECT * FROM `order`")
    List<Order> findAll();


    @Select("SELECT * FROM `order` WHERE id = #{id}")
    Order findById(Long id);

    @Update("UPDATE `order` SET status = #{status} WHERE id = #{orderId}")
    void updateStatus(@Param("orderId") Long orderId, @Param("status") String status);

    @Delete("DELETE FROM `order` WHERE id = #{id}")
    void delete(Long id);

    @Insert("INSERT INTO `order`(user_id, total_price, status, created_at) VALUES(#{userId}, #{totalPrice}, #{status}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Order order);
}
